{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "164d7cea-8b1f-47ba-8ee0-599bf4157d74",
   "metadata": {},
   "source": [
    "# 1 ndarray"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "eb54ab7d-6397-4030-9243-266bf6550b78",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "raw",
   "id": "65e50592-5d97-4c53-8d3a-3e0c34175ece",
   "metadata": {},
   "source": [
    "1）np.ones(shape, dtype=None, order='C')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "56bdea73-70f9-481c-a9ec-fd0267ee3377",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.array([1, 2, 3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "43c00e58-4fa8-4e64-ad1d-a404ec8727c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "15b48bcf-7a42-4951-8b47-6d0d00a258fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [2, 3, 4],\n",
       "       [3, 4, 5]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([[1,2,3],[2,3,4],[3,4,5]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e5db2a47-bd21-4c5e-8c03-527ac479109d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [1., 1., 1.]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape=(2,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cffa3b55-28c8-492a-935b-0f9cb656ba74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 1., 1.])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape=(3,))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c9061d74-f7c3-4d9a-a1f4-3a62f592990d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape=(1,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5922767e-702d-420b-bd9f-ac913d8004c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.],\n",
       "       [1.],\n",
       "       [1.]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape=(3,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f67ef2c1-36e5-496f-9893-faf2b7aa4e8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 1., 1.])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape=(3,))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "47b0b9ff-e8be-417c-bdc0-ffbcd78e920f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape=(1,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "782cb7e3-6e2f-47b4-93e9-d30791c6b785",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1],\n",
       "       [1, 1],\n",
       "       [1, 1]], dtype=int8)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape=(3,2), dtype=np.int8)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b92a146f-e7ea-4ad8-92ff-8ba6c8513479",
   "metadata": {},
   "source": [
    "2)np.zeros(shape, dtype, order='C'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "53aabd33-352d-4376-a9f4-4f4a4384e3e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0],\n",
       "       [0],\n",
       "       [0]], dtype=uint8)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.zeros(shape=(3,1), dtype=np.uint8)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34b1180d-596e-4b35-87c1-3a6bc065d1fb",
   "metadata": {},
   "source": [
    "3）np.full(shape,fil_value,dtype=None,order='C')  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bc6faed5-4b4a-453f-a84a-b3cf83204ee6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 6, 6],\n",
       "       [6, 6, 6],\n",
       "       [6, 6, 6]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.full(shape=(3,3),fill_value=6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21050767-eeaf-41e8-89f9-abd1c9b2cb6d",
   "metadata": {},
   "source": [
    "4）np.eye(N, M=None, k=0, dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ab8432d6-57e8-4057-a324-0e1ff4dc7bee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0.],\n",
       "       [0., 1., 0.],\n",
       "       [0., 0., 1.]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.eye(N=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "23aef796-8925-45f3-9f22-9c6c7c349159",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 1., 0.],\n",
       "       [0., 0., 1.],\n",
       "       [0., 0., 0.]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.eye(N=3, k=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a3536bca-aa3b-4e29-89d4-5d9a800b32e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0.],\n",
       "       [1., 0., 0.],\n",
       "       [0., 1., 0.]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.eye(N=3, k=-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bc77e92-2798-47f2-85e1-8292e623d3cb",
   "metadata": {},
   "source": [
    "\n",
    "5）np.linspace(start,stop,num=50,endpoint=True,restep=False,dtype=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "67737905-fdf0-4661-98bc-7f31e364ba9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,10,11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a4f96eb2-6f50-46e8-8d08-3e01b8939665",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0.,  10.,  20.,  30.,  40.,  50.,  60.,  70.,  80.,  90., 100.])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,100,11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "cf006a93-9779-4bc1-959a-81d7609e3709",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.        ,  7.69230769, 15.38461538, 23.07692308, 30.76923077,\n",
       "       38.46153846, 46.15384615, 53.84615385, 61.53846154, 69.23076923,\n",
       "       76.92307692, 84.61538462, 92.30769231])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,100,13,endpoint=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2ffb1ddb-be8d-453e-8b57-e249e648ee08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0., 120., 240., 360.])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,360,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "05088ad5-e5fc-4f43-8eae-add44ad4e47d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0.,  90., 180., 270.])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,360,4,endpoint=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdde19d7-bb97-435c-98ad-3075ee8641c6",
   "metadata": {},
   "source": [
    "6）np.arange([start,]stop,[step,]dtype=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c9123e41-d4f4-46a6-b6e5-fdfec04fc295",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(0, 100, step=10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a17785cd-795c-4542-aa42-acfc409c4687",
   "metadata": {},
   "source": [
    "7）np.random.randint(low, high=None, size=None, dtype='l')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "91cea1d7-fc8c-4240-be0d-225b6a71bbe5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[76, 21, 33, 35, 91],\n",
       "       [52,  0, 48, 20, 40],\n",
       "       [77, 36, 39, 93, 58]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(low=0, high=100, size=(3,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e8c7eaa3-877e-4be3-bf7b-c664e74077c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 0, 0, 3, 6, 1, 6, 5, 9, 1])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(0,10, size=(10,))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f25c085a-4a21-4b7f-84e8-6b1760d4cc3a",
   "metadata": {},
   "source": [
    "8)正态分布函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ab6ef144-4c52-4dd8-b381-289850641f57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([189.36194812, 158.37459658, 182.77829832, 169.86593845,\n",
       "       178.74149144, 182.95486873, 167.80697966, 167.13277772,\n",
       "       187.72812242, 177.56678778])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.normal(loc=175, scale=10, size=(10,))  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ef9e75fd-788b-4d23-8c45-96b1359798ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = np.random.randn(10,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "27d65196-2e57-4a0f-93a2-ae3a27921602",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "600b9e1f-d63e-49e8-bf4c-a07849105727",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[1., 2., 0., 1., 2., 3., 1., 0., 0., 0.],\n",
       "        [1., 0., 0., 1., 1., 4., 1., 2., 0., 0.],\n",
       "        [0., 1., 1., 2., 2., 2., 1., 0., 0., 1.],\n",
       "        [0., 0., 2., 2., 4., 1., 1., 0., 0., 0.],\n",
       "        [0., 0., 1., 1., 2., 4., 0., 0., 0., 2.]]),\n",
       " array([-1.58238667, -1.16184428, -0.74130189, -0.3207595 ,  0.0997829 ,\n",
       "         0.52032529,  0.94086768,  1.36141007,  1.78195247,  2.20249486,\n",
       "         2.62303725]),\n",
       " <a list of 5 BarContainer objects>)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAH0xJREFUeJzt3X9MVfcd//HXnejFrYATC14iVEw7SqG2Dpp5m6K2rBhYTF3M0uXbqP3hElrU6Q1hRf9obWNoFtJRo0JdUWpMq0uuti5SI0kFXKuJKKRmQ9Im1Evopcw25Va+3UXo/f7Rb292B/fiuaAfuTwfyfnjnPM5nPctaJ+5P8QWCAQCAgAAMOQnpgcAAADTGzECAACMIkYAAIBRxAgAADCKGAEAAEYRIwAAwChiBAAAGEWMAAAAo+JMD3Ajvv/+e33xxRdKSEiQzWYzPQ4AALgBgUBA3377rdLS0vSTn4R//mNKxMgXX3yh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JLIBDQpk2bdOzYMTU3NyszM9P0SNMWMTJNeTweff311/J4PBoZGVFHR4ck6e6779Ydd9xhdjjI5XJp7dq1ys/Pl9Pp1L59++TxeFRaWmp6NIRx7do1ffbZZ8H97u5udXR0aO7cucrIyDA4GcIpKyvTO++8o/fff18JCQnBZyOTkpI0e/Zsw9NNL3y0d5p6+umn9fbbb486fvr0aa1YseLWD4RR9u7dqz//+c/yer3Kzc3VX/7yFz5ueBtrbm7Wo48+Our4+vXr1dDQcOsHwrjCvQfrwIEDevrpp2/tMNMcMQIAAIzi0zQAAMAoYgQAABhFjAAAAKOIEQAAYBQxAgAAjCJGAACAUcQIAAAwihgBAABGESMAAMAoYgQAABhFjAAAAKOIEQAAYNT/A0Dr2YIXCuMAAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90088fb7-e706-452d-adc5-9860a86105ef",
   "metadata": {},
   "source": [
    "9)np.random.random(size=None)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "9de57b46-69ee-43b3-8b69-ea94e1e85feb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.93643924, 0.02321861, 0.99048851, 0.73810045, 0.46436508,\n",
       "       0.05035666, 0.35313474, 0.36634458, 0.90060635, 0.94683617])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.random(size=(10,))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "670a9bd4-4af3-4d5f-96ed-06b7b3bec51d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.18610793, 0.22418838, 0.54049939, 0.68830008, 0.85523134],\n",
       "       [0.20064188, 0.66271968, 0.48971627, 0.27843861, 0.6547791 ],\n",
       "       [0.4381433 , 0.02560395, 0.60317217, 0.69133547, 0.14694168],\n",
       "       [0.70584031, 0.6603605 , 0.4634783 , 0.48033188, 0.58693875],\n",
       "       [0.89838414, 0.37858992, 0.24226658, 0.57016622, 0.59176146],\n",
       "       [0.34646816, 0.22477423, 0.86594576, 0.48838523, 0.21417589],\n",
       "       [0.35175464, 0.92326067, 0.86652162, 0.5129681 , 0.79814916],\n",
       "       [0.78806145, 0.98166008, 0.46396682, 0.69147927, 0.55244526],\n",
       "       [0.48647997, 0.0878635 , 0.48776255, 0.30354032, 0.92522113],\n",
       "       [0.67062431, 0.37313741, 0.45597554, 0.38650531, 0.78252308]])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.random(size=(10, 5))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddb47651-a3f0-48dc-96d3-9158bf769274",
   "metadata": {},
   "source": [
    "10）np.random.permulation(10)生成随机索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "feea897d-286d-469e-9659-ca4cb6642a64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([7, 1, 0, 5, 2, 4, 3, 6, 8, 9])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.permutation(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "6e78ba53-2a7e-45b9-9ae5-b70912b86546",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 0, 4, 2, 1])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.permutation(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56e50a97-d99d-41f8-8dd9-2740430937b5",
   "metadata": {},
   "source": [
    "11)随机种子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "77611f99-76a1-4599-8aff-4f704cf81ec2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 0, 3, 3, 7])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.seed(0) # 添加一个种子\n",
    "\n",
    "np.random.randint(0, 10, size=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d6687e9-54ae-48e4-b5ae-ecbb2d059f63",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "f59b601b-d359-4df2-84d2-b344a8a2a496",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-5, -3, -2,  3],\n",
       "       [-4, -2, -2, -2],\n",
       "       [ 2, -5, -4,  4]])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(-5, 5, size=(3,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0ba124d-18ac-403a-be05-7ae44c12f6c4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "0cb24616-17b7-43f0-af74-c7e524c68f3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  3.,  6.,  9., 12.])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0, 15, 5, endpoint=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "5fd547b6-c1a8-4522-aef3-035ed7c45677",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  3,  6,  9, 12])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(0, 15, step=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "7c41cb93-cbea-492b-8e49-2a73bf5e6460",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('float64')"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = np.random.random(size=(100, 100, 3))\n",
    "data.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "9b18e712-8ae6-4100-9e2e-dedd090034ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.78539816, 1.57079633, 2.35619449, 3.14159265,\n",
       "       3.92699082, 4.71238898, 5.49778714])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0, 2*np.pi, num=8, endpoint=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b561d402-6f7f-4c6a-b644-7f563f79fbdd",
   "metadata": {},
   "source": [
    "# 2 ndarray的读写操作\n",
    "## 2.1索引访问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "3a6fc3bd-2cb8-4751-8d02-cdaec8939ebf",
   "metadata": {},
   "outputs": [],
   "source": [
    "l1 = [1,2,3,4,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "f7ec5537-21fd-479b-a91b-4c6533462378",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l1[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "56e18d65-fdfc-49a5-875c-6fde51ee5c53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l1[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "40cb789b-1111-426b-b1fe-1d424fd5c0d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[1, 2, 3], [2, 3, 4]]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l2 = [[1,2,3],[2,3,4]]\n",
    "l2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "8f773e9a-f0c0-47c9-999c-62d5140bacc5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l2[1][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "7349b8fc-b905-46b0-a759-9e75f1a95072",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([8, 6, 0, 2, 7, 4, 2, 1, 3, 8])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr4 = np.random.randint(0, 10, size=10)\n",
    "arr4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "1f93b051-cd49-4544-accd-92f93d3c4934",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8, 8)"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr4[0], arr4[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "c13ee39a-0f29-4ee9-bf71-6f43444b103e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5, 9, 7, 3],\n",
       "       [7, 4, 7, 3],\n",
       "       [5, 6, 4, 5]])"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr5 = np.random.randint(0,10,size=(3,4))  \n",
    "arr5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "82e50ee0-2974-424e-a0aa-b766073e2ffc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 6, 4, 5])"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr5[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "2e49aa41-2734-49c9-a7c0-071cb53bb754",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr5[2][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "08f89019-b30d-4011-8fd3-d01354ff317b",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr5[2][1] = 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "b2e23257-c1b9-4798-9720-82aceb96d029",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  5,   9,   7,   3],\n",
       "       [  7,   4,   7,   3],\n",
       "       [  5, 100,   4,   5]])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "dd728d16-ffba-43ac-a680-73bf84c44ab2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr5[2, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40e35793-32fe-4502-a674-2942b0e3f1b6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "db629911-85c9-4838-b031-d02d7b1ab0ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([85, 16,  3, 92, 70, 86, 27, 18, 87, 90])"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1 = np.random.randint(0, 100, size=10)\n",
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "d21217ef-d30a-40f6-b2d5-63f671d5bcca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(16, 3)"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1[1], arr1[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "5ce5d453-94ae-41b1-be85-9ad37e41b9b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([16,  3])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = [1, 2]\n",
    "arr1[index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "fda679f3-4ca4-4536-b1de-c753fd813f83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([16,  3, 16,  3, 16,  3])"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index1 = [1, 2, 1, 2, 1, 2]\n",
    "arr1[index1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "6add7891-af2d-4278-9bcb-37483e2ce6be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([16,  3, 90, 70, 92, 86, 87, 85, 18, 27])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ndarray 也同时作为 ndarray对象的索引列表\n",
    "index2 = np.random.permutation(10)\n",
    "\n",
    "# 对原数组进行随机排序\n",
    "arr1[index2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "68cb861d-f59d-4711-87ae-2ac1d5af29d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 6, 0])"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 在原始数据中，随机取3个数\n",
    "random_index = np.random.permutation(10)[[0,1,2]]\n",
    "\n",
    "random_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "072ba70e-51d6-4319-bc14-794df1f45212",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([86, 27, 85])"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1[random_index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "070f582d-fb98-41ed-9731-3ac3033bdfa9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 1])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 在原始数据中，随机取3个数\n",
    "random_index2 = np.random.randint(0, 10, size=3)\n",
    "\n",
    "random_index2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "1a315023-8e63-43e2-a2d6-0e8ee637ccb3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([85, 16, 16])"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1[random_index2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a17bad22-c971-42cf-b352-a4427b64273a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "2277401f-6b0e-48a7-9285-22291093aa9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[95, 14, 46, 56, 58],\n",
       "       [72, 65, 91, 73, 65],\n",
       "       [ 3, 48, 63, 46, 33],\n",
       "       [ 1, 35, 65, 97, 68],\n",
       "       [26, 50, 27, 47, 10]])"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2 = np.random.randint(0, 100, size=(5,5))\n",
    "arr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "9f59fc9d-3052-430f-81f3-1212afb7a683",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[95, 14, 46, 56, 58],\n",
       "       [72, 65, 91, 73, 65]])"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取前两行\n",
    "arr2[[0, 1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "84436f9b-a00a-46e7-8892-90c91595facd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[95, 14],\n",
       "       [72, 65],\n",
       "       [ 3, 48],\n",
       "       [ 1, 35],\n",
       "       [26, 50]])"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取前两列\n",
    "arr2[:,[0, 1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3dece13b-d34b-40e9-a08e-22868185e51b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "1ee0dac7-2df9-47b2-a684-767714b942ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([85, 16,  3])"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 访问前3个元素0到3\n",
    "arr1[0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "680a8b91-199e-4d21-8d3b-fa0e485cf70e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([27, 18, 87, 90])"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 访问后四个元素\n",
    "arr1[-4:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "48b290da-790d-4639-9321-c1148602e59d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([85, 16,  3, 92, 70, 86, 27, 18, 87, 90])"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "b65b27cd-7844-4dbd-bd71-5d9d10dd5932",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([85,  3, 70, 27, 87])"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 访问从头开始到一直到最后一个元素，步长2\\\n",
    "# arr1[start : end : step]\n",
    "arr1[0:-1:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "96f92427-d5d5-4cb0-bdcc-823a38a88800",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([90, 87, 18, 27, 86, 70, 92,  3, 16, 85])"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从后往前倒序取 \n",
    "arr1[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "750dfed4-df61-4cc1-94d7-22631174a8ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([90, 18, 86, 92, 16])"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从后往前倒序取 ，且隔一个取一个\n",
    "arr1[::-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15b55c87-cbd2-4bf2-9d6e-ec18bbbcae17",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b64e180-52b1-4e70-91a1-2a1b99995ada",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6619183-85d2-4516-be03-eebd34763905",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55bb1b90-dff6-478e-a987-f3e1b5ef70bb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f4cc5db-4d9b-48d4-9b6d-af1e3ee9047f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
